__author__ = 'wenke'
import xlrd
import os
import sys
import commands
stuid_set = []

working_dir = os.getcwd()

homework = raw_input('Enter the homework name: ')

sheet_id = int(raw_input('Enter the sheet id from which the name list is read. 0 for 60-79, 1 for zeros: '))

if (sheet_id < 0) or (sheet_id > 1):
	print 'Invalid sheet id'

data_1 = xlrd.open_workbook("%s_makeup.xlsx" % (homework))
table_1 = data_1.sheets()[sheet_id]
for i in range(len(table_1.col_values(0))):
    stuid_set.append(table_1.col_values(0)[i])
    print "Read student %s" % (stuid_set[i])

for stuid in stuid_set:
	stu_path = "../homeworks/%s_%s" % (stuid, homework)
	if os.path.exists(stu_path):
		os.chdir(stu_path)
		os.system("cp ../../makeup/%s_makeup%s.docx %s_makeup%s.docx" % (homework, sheet_id, homework, sheet_id))
		os.system("git add .")
		os.system("git commit -m \"makeup\"")
		os.system("git push")
		os.chdir(working_dir)
	else:
		print "Path %s/%s does not exist." % (working_dir, stu_path)